package com.lnsoft.cac.server.handle.codec.frameMessage;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.NonNull;

@Data
/**
 * 通信流量数据报-升级结束报文
 * */
public class Upgrade_End_Cfm {
    private int Rev_Status = 0xFF;         //1byte             数据发送状态：①0xFF成功②0x00失败，表示未通过MD5校验


    public ByteBuf toByteBuf() throws Exception{
        if (Rev_Status != (byte)0xFF && Rev_Status != (byte)0x00) {
            throw new Exception("数据发送状态 设置异常");
        }
        ByteBuf bf = Unpooled.buffer();
        bf.writeByte(Rev_Status);
        return bf;
    }




    //  解析 [升级结束报文-确认] 帧报文内容区 到消息体中
    public static Upgrade_End_Cfm decFrameBody(@NonNull byte[] frameBody) throws Exception {
        ByteBuf bf = Unpooled.wrappedBuffer(frameBody);
        Upgrade_End_Cfm msg = new Upgrade_End_Cfm();
        int len = frameBody.length;
        if (len == 0) {
            return null;
        }
        if (26 != len) {
            throw new Exception("frameBody 数据异常");
        }
        msg.setRev_Status(bf.getUnsignedByte(0));
        return msg;
    }

}
